from sqlalchemy import create_engine


def create_mysql_datasource(user: str, password: str, host: str, port: str, database_name: str, pool_size: int, max_overflow: int):
    db_connection_str: str = f"mysql+pymysql://{user}:{password}@{host}:{port}/{database_name}"
    db_engine = create_engine(db_connection_str, pool_size=pool_size, max_overflow=max_overflow)
    return db_engine

#如果sqlite的数据库名称没有配置，则默认按照内存模式启动sqlite
def create_sqlite_datasource(database_name: str =None):
    if not database_name :
        db_connection_str: str = "sqlite:///:memory:"
    else:
        db_connection_str: str = f"sqlite:///{database_name}"
    db_engine = create_engine(db_connection_str)
    return db_engine